clear all
version 16.1


****************************************************
/* the sample is firms that belong to one (or more) of g28_plus groups */
use ../tmp/sample_090122.dta, clear

cap drop regionfirmTG
egen regionfirmTG = tag(regionfirmID)
count if regionfirmTG == 1 
count if regionfirmTG == 1 & ftt_ts1s < .
count if regionfirmTG == 1 & firm_treatment < .
count if regionfirmTG == 1 & mints1 < -1.64
count if ftt_ts1p > 1.64 & ftt_ts1p < . & regionfirmTG == 1 & firm_treatment < .
count if ftt_ts1s > 1.64 & ftt_ts1s < . & regionfirmTG == 1 & firm_treatment < .
count if ((ftt_ts1p < -1.64 & ftt_ts1p < . )|( ftt_ts1s > 1.64 & ftt_ts1s < .)) & regionfirmTG == 1 & firm_treatment < .
graph drop _all


bys regionfirmTG g28_plus: egen N_firms_g28_plus = total(regionfirmTG & firm_treatment < .)
tabstat N_firms_g28_plus, by(g28_plus) s(n max)
keep if regionfirmTG == 1

tempfile tempf002
preserve
	import excel ../data/sales_firm_license.xlsx, first clear 
	drop _merge
	keep if no_license < .
	save `tempf002', replace
	tab no_license
restore
merge m:1 nm_firm no_license using `tempf002'

gen sales_thousand = sales / 1000
gen profits_thousand = profit / 1000
tabstat sales_thousand profits_thou engineers if firm_treatment < . & (g28_plus != 21 & g28_plus != 24) /*& _merge == 3*/ , by(firm_treatment) ///
	s(mean sd min max n ) columns(statistics) format("%11.3gc")   
	
estpost sum sales_thousand profits_thou engineers ftt_ts1s ftt_ts1p if firm_treatment == 1 & (g28_plus != 21 & g28_plus != 24) /*& _merge == 3*/
est store treatment
estpost sum sales_thousand profits_thou engineers ftt_ts1s ftt_ts1p if firm_treatment == 0 & (g28_plus != 21 & g28_plus != 24)/*& _merge == 3*/
est store control

label var sales_thousand "\raisebox{-2.2mm}[0mm][0mm]{Annual Sales}"
label var profits_thousand "\raisebox{-2.2mm}[0mm][0mm]{Annual Profits}"
label var engineers "\raisebox{-2.2mm}[0mm][0mm]{\# Engineers}"
label var ftt_ts1s "\raisebox{-2.2mm}[0mm][0mm]{\$t\$-stat (\$\esp \left[\Delta_{i,t}^p\right]\$)}"
label var ftt_ts1p "\raisebox{-2.2mm}[0mm][0mm]{\$t\$-stat (\$\esp \left[\tilde\Delta_{i,t}^s\right]\$)}"

estout treatment control using ../tables/summary_stats_firms.tex, ///
		cells("mean(fmt(%09.2fc)) a(v()) " ///
		"sd(par fmt(%9.2fc)) .") label replace collabels(none) style(tex) ///
			mlabels(,none) stats(N, labels("\$N\$") fmt(%8.0gc))
